import React, { Component } from 'react';
import _ from 'lodash';
import moment from 'moment';
import Former, { validate } from '../../../components/Former';
import Button from '../../../components/Button';
import { idCardRule, mobileRule } from '../../../utils/rules';
import { gender } from '../../../common/baseData';

export default class From extends Component {
  _validate = () => {
    validate((err, val) => {
      if (!err && _.isFunction(this.props.onSubmit)) {
        val.customerId = this.props.item.customerId;
        val.type = 3;
        this.props.onSubmit(val);
      }
    });
  };
  render() {
    const fields = [
      {
        label: '任务名称',
        placeholder: '请输入任务名称',
        type: 'TextInput',
        key: 'title',
        initialValue: `拜访客户 ${this.props.item.name}`,
        rules: [{ require: true }]
      },
      {
        label: '计划时间',
        placeholder: '请选择计划时间',
        type: 'Date',
        key: 'scheduledTime',
        mode: 'datetime',
        initialValue: moment().add(1, 'd').format('YYYY-MM-DD HH:mm'),
        minDate: moment().format('YYYY-MM-DD HH:mm'),
        maxDate: moment().add(7, 'd').format('YYYY-MM-DD HH:mm')
      },
      {
        type: 'Title',
        title: '任务描述'
      },
      {
        placeholder: '请输入任务名称',
        type: 'TextArea',
        key: 'description',
        initialValue: `拜访客户 ${this.props.item.name}`,
      },
    ];
    return (
      <Former
        fields={fields}
        bottom={
          <Button
            onPress={this._validate}
            type="primary"
            title="提交新客户资料"
          />
        }
      />
    );
  }
}
